import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';
import 'package:meal/constant/fonts.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/sp.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'event/event_model.dart';

main() async {
  WidgetsFlutterBinding.ensureInitialized();

  /// 初始化本地存储
  await SpUtils.getInstance();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      theme: ThemeData(
          fontFamily: Fonts.yaHei,
          brightness: Brightness.dark,
          appBarTheme: const AppBarTheme(systemOverlayStyle: SystemUiOverlayStyle.dark)),
      debugShowCheckedModeBanner: false,
      showSemanticsDebugger: false,
      title: '订餐外卖',
      transitionDuration: const Duration(milliseconds: 500),
      defaultTransition: Transition.cupertino,
      getPages: RouteGet.getPages,
      initialRoute: RouteGet.home,
      supportedLocales: [BrnResourceZh.locale],
      localizationsDelegates: [
        RefreshLocalizations.delegate,
        BrnLocalizationDelegate.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      routingCallback: (Routing? routing) {
        if (routing?.previous == RouteGet.userLoginLogin) {
          return globalBus.fire(LoginBackEvent());
        }
      },
      navigatorObservers: [
        GetObserver((Routing? routing) {
          globalBus.fire(ClosedOverlayEntryEvent());
        }, Routing()),
      ],
    );
  }
}
